var enterprise = {};
enterprise.op = {
	deleteSubject : function(id){
		$.post(forum.baseURL + "/enterprise/forum/subject/" + id, {_method:'delete'}, function(json){
			if(json.process == "success"){
				alert("删除成功");
				location.href=location.href;
			}
		},"json");
	},

	goodSubject : function(id, bool){
		$.post(forum.baseURL+"/enterprise/forum/subject/" + id, {good:bool,_method:'put'}, function(json){
			if(json.process == "success"){
				if(bool){
					alert("已经成为精品主题 ");
				} else {
					alert("已经不是精品主题");
				}
				location.href=location.href;
			}
		},"json");
	},

	topSubject : function(id, bool, level){
		$.post(forum.baseURL+"/enterprise/forum/subject/" + id, {top:bool,level:level,_method:'put'}, function(json){
			if(json.process == "success"){
				if(bool){
					alert("已经成为置顶主题 ");
				} else {
					alert("已经不是置顶主题");
				}
				location.href=location.href;
			}
		},"json");
	},
	
	publishReply : function(subjectId){
		$("input[type='submit']").attr("disabled", "disabled");
		$('span.error').remove();
		var content = KE.util.getData("topic_content");
		var data = {content:content, subjectId:subjectId};
		$.post(forum.baseURL + "/enterprise/forum/reply", data, function(json){
			if(json.process == "success"){
				var html;
				content = content.replace(new RegExp('event="thumbImg"','gm'),'onload="forum.thumbImg(this)"');
				if(json.accountId == 1){
					html = '<div class="content_wrap"><i class="floor">' + json.floor + '楼</i><div class="content">' + content + '</div></div><div class="info"><a href="#"><img src="' + forum.baseURL + json.photoPath + '"/></a><span class="nickname">' + json.nickname + '</span></div><div class="clear"></div><div class="time">' + json.date + '</div>';	
				} else {
					html = '<div class="content_wrap"><i class="floor">' + json.floor + '楼</i><div class="content">' + content + '</div></div><div class="info"><a href="' + forum.baseURL + '/member/' + json.accountId + '?action=profile"><img src="' + forum.baseURL + json.photoPath + '"/></a><a href="' + forum.baseURL + '/member/' + json.accountId + '?action=profile" class="nickname">' + json.nickname + '</a></div><div class="clear"></div><div class="time">' + json.date + '</div>';	
				}
				$("div[class=time]:last-child").after(html);
				forum.dialog.message({content:'发表成功',close:false,width:200,height:80});
				//清空编辑器
				KE.g['topic_content'].iframeDoc.open();
				KE.g['topic_content'].iframeDoc.write(KE.util.getFullHtml('topic_content'));
				KE.g['topic_content'].iframeDoc.close();
				KE.g['topic_content'].newTextarea.value = '';
			} else if(json.message != undefined) {
				$("input[type='submit']").after('<span class="error" style="color:red">*'+ json.message + '</span>');
			} else {
				$("input[type='submit']").after('<span class="error" style="color:red">*请输入回复内容后再发表</span>');
			}
			$("input[type='submit']").removeAttr("disabled");
		},"json");
	},

	deleteReply : function(id){
		$.post(forum.baseURL + "/enterprise/forum/reply/" + id, {_method:'delete'}, function(json){
			if(json.process == "success"){
				alert("删除成功");
				location.href=location.href;
			}
		},"json");
	},
	
	hideReply : function(id, bool){
		$.post(forum.baseURL + "/enterprise/forum/reply/" + id, {hide:bool,_method:'put'}, function(json){
			if(json.process == "success"){
				if(bool){
					alert("已经隐藏");
					location.href=location.href;
				} else {
					alert("已经显示");
					location.href=location.href;
				}
			}
		},"json");
	},

	hideSubject : function(id, bool){
		$.post(forum.baseURL + "/enterprise/forum/subject/" + id, {hide:bool,_method:'put'}, function(json){
			if(json.process == "success"){
				if(bool){
					alert("已经隐藏");
					location.href=location.href;
				} else {
					alert("已经显示");
					location.href=location.href;
				}
			}
		},"json");
	},
	
	forbidReply : function(subjectId, bool){
		$.post(forum.baseURL + "/enterprise/forum/subject/" + subjectId, {forbidReply:bool,_method:'put'}, function(json){
			if(json.process == "success"){
				if(bool){
					alert("该主题已禁止回复");
					location.href=location.href;
				} else {
					alert("该主题已允许回复");
					location.href=location.href;
				}
			}
		},"json");
	}
};